﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PGMHelper;
using Spectrum;

namespace SpectrumTestForm
{
    public partial class ArtiWaveForm : Form
    {
        /// <summary>
        /// 人工波对象
        /// </summary>
        ArtiWaveObj waveObj { set; get; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ArtiWaveForm()
        {
            InitializeComponent();
            //设定外观
            this.SpectrumChart.SetApperance(StringAlignment.Near, false, isLegendAvailabel: false);
            this.WaveChart.SetApperance(StringAlignment.Near, false, isLegendAvailabel: false);
            //设定格式
            this.WaveChart.SetAxisFormat(ChartAxisType.AxisX, AxisFormat.Normal, 0);
            this.WaveChart.SetAxisFormat(ChartAxisType.AxisY, AxisFormat.Normal, 3);
            this.SpectrumChart.SetAxisFormat(ChartAxisType.AxisX, AxisFormat.Normal, 0);
            this.SpectrumChart.SetAxisFormat(ChartAxisType.AxisY, AxisFormat.Normal, 3);
            //设定边界值
            this.SpectrumChart.SetAxisBroundary(ChartAxisType.AxisX, 0, 6);
            //采用广东规程
            ArtiWaveParam.CodeSpectrumType = CodeSpectrumEnum.GD2020;
            //初始化
            this.waveObj = new ArtiWaveObj(this.GetCodeSpectrum(), "1", 2, 25, 30, 0.02);
            //绘图
            this.waveObj.ToChart(this.WaveChart, this.SpectrumChart);
        }

        /// <summary>
        /// 迭代测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TestButton_Click(object sender, EventArgs e)
        {
            this.waveObj.IterationGroupRun(0, (i, s)=> { ++i; });
            this.waveObj.ToChart(this.WaveChart, this.SpectrumChart);
        }

        /// <summary>
        /// 设定规范反应谱
        /// </summary>
        private SpectSet GetCodeSpectrum()
        {
            //设定规范反应谱
            SpectSet specturm = new GBCodeSpectrum(ArtiWaveParam.Tg,
                ArtiWaveParam.AfaMax,
                ArtiWaveParam.DampRatio, ArtiWaveParam.is6GBHorizontal,
                ArtiWaveParam.PeriodLength + 1, ArtiWaveParam.PeriodDelta);
            //若为广东省规程
            if (ArtiWaveParam.CodeSpectrumType == CodeSpectrumEnum.GD2020)
                specturm = new GDCodeSpectrum(ArtiWaveParam.Tg,
               ArtiWaveParam.AfaMax,
               ArtiWaveParam.DampRatio,
               ArtiWaveParam.PeriodLength + 1, ArtiWaveParam.PeriodDelta,
               ArtiWaveParam.SoilCondition);
            return specturm;
        }
    }
}
